package screen;


import java.awt.*;
import java.awt.event.*;

public class AwtImage extends Frame{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	Image myImage;
	
	public static void main(String[] args) throws InterruptedException {
	  /*AwtImage ai =*/ new AwtImage();
	}

  	public AwtImage() throws InterruptedException{
	  	//super("Screen Sharing");
		MediaTracker mt = new MediaTracker(this);
		myImage = Toolkit.getDefaultToolkit().getImage("ScreenGrab.jpg");
		mt.addImage(myImage,0);
		mt.waitForID(0);
		int width = myImage.getWidth(null);
		int height = myImage.getHeight(null);
		//DEBUG System.out.println("The width of image: " + width);
		//DEBUG System.out.println("The height of image: " + height);
		//set initial window size
		setSize(width,height);
		setVisible(true);
  		addWindowListener(new WindowAdapter(){
	  		public void windowClosing(WindowEvent we){
	  			dispose();
			}
		});
	}
  
	public void update(Graphics g){
	  paint(g);
	}
  
	public void paint(Graphics g){
		if(myImage != null)
			//To simply print the image:
			//g.drawImage(myImage, 0, 0, this);
			
			//This fits a 2560x1440 image on a 1600x900 size 'image', then gets drawn in the window created above
			g.drawImage(myImage, 0, 0, 1280, 800, 0, 0, myImage.getWidth(null), myImage.getHeight(null), this);
		else
			g.clearRect(0, 0, getSize().width, getSize().height);
	}
	
	
}
